'use strict';

const mongoose = require('mongoose'),
    foodAdModel = mongoose.model('FoodAd');

module.exports = {
    createFoodAdByMerchant: createFoodAdByMerchant, 
    getFoodAdByMerchant: getFoodAdByMerchant,
    foodAdUpdateStatus: foodAdUpdateStatus,
}


function createFoodAdByMerchant(foodAd,callbakck){
    foodAdModel.create(foodAd,function(error,data){
        callback(null,data);
    });
}


function getFoodAdsByMerchant(merchant,callbakck){
    foodAdModel.find({'merchant': merchant},function(err,doc){
       callbakck(null,doc);
    });

} 


function getFoodsAdByfoodAdUpdateStatus(foodAd,callbakck){
   foodAdModel.updateOne({'_id':foodAd._id},{
           food : foodAd.food,
           merchant  : foodAd.merchant,
           status : foodAd.status,
           applytime : foodAd.applytime,
           autitTime : foodAd.autitTime,
   },function(err, doc){
        callback(null,doc);
   });    


}